﻿using System;
using System.Linq;
using System.Numerics;
using MartinRL.ProjectEuler.Sequences;

namespace MartinRL.ProjectEuler.Tests
{
    public class ShootingRange
    {
        public void target_practice()
        {
            Console.WriteLine(2.Pow(15));
            Console.WriteLine(new BigInteger(new byte[] {0, 0, 1}) / 2);

            Console.WriteLine(2.Pow(0));
            Console.WriteLine(new BigInteger(new byte[] {1}));

            Console.WriteLine(2.Pow(8));
            Console.WriteLine(new BigInteger(new byte[] {0, 1}));

            Console.WriteLine(2.Pow(16));
            Console.WriteLine(new BigInteger(new byte[] {0, 0, 1}));

            Console.WriteLine(1000 % 8);
            Console.WriteLine(1000 / 8);

            Console.WriteLine(
                new BigInteger((new string('0', 125) + "1").ToCharArray().Select(c => c.ParseAsByte()).ToArray()));
        }

        public void TargetPractice()
        {
            Console.WriteLine(Enumerable.Range(0, 1000).Last());
        }

        public void TargetPractice2()
        {
            CollatzSequence.NewSequence(8).ForEach(Console.WriteLine);
        }

        public static void Problem014_alternative()
        {
            var max = 0;
            var maxnr = 0;

            for (var i = 1; i < 1000000; i++)
            {
                long a = i;
                var j = 1;

                while (a != 1)
                {
                    a = ((a & 1) == 1) ? (3 * a + 1) : (a >> 1);
                    j++;
                }

                if (j > max)
                {
                    max = j;
                    maxnr = i;
                }
            }

            Console.WriteLine(maxnr);
        }

        public static void p18_to_binary()
        {
            Console.WriteLine(Convert.ToString(2, 2).PadLeft(3, '0'));
        }
    }
}